package com.situ.web.service.impl;

import java.util.List;

import com.situ.web.dao.IStudentDao;
import com.situ.web.dao.impl.StudentDaoImpl;
import com.situ.web.entity.PageInfo;
import com.situ.web.entity.Student;
import com.situ.web.service.IStudentService;

public class StudentServiceImpl implements IStudentService{
	private IStudentDao studentDao = new StudentDaoImpl();

	@Override
	public List<Student> findAll() {
		return studentDao.findAll();
	}

	@Override
	public boolean deleteById(Integer id) {
		int count = studentDao.deleteById(id);
		return count == 1 ? true : false;
	}

	@Override
	public boolean insert(Student student) {
		int count = studentDao.insert(student);
		return count == 1 ? true : false;
	}

	@Override
	public Student findById(Integer id) {
		return studentDao.findById(id);
	}

	@Override
	public boolean update(Student student) {
		int count = studentDao.update(student);
		return count == 1 ? true : false;
	}

	@Override
	public PageInfo findByPage(int pageNo, int pageSize) {
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNo(pageNo);
		pageInfo.setPageSize(pageNo);
		
		int totalCount = studentDao.getTotalCount();
		int totalPage = (int) Math.ceil((double)totalCount / pageSize);
		pageInfo.setTotalPage(totalPage);
		
		int offset = (pageNo - 1) * pageSize;
		List<Student> list = studentDao.fingByPage(offset, pageSize);
		pageInfo.setList(list);
		
		return pageInfo;
	}

}
